package com.palm.dev.mode;

import com.alibaba.fastjson.annotation.JSONField;
import org.sagacity.sqltoy.utils.StringUtil;

import java.util.ArrayList;
import java.util.List;

public class Column {
    /*
  	<attr name="Name">村级粪污和污水处理设施设备</attr>
    <attr name="Code">Fwscl</attr>
    <attr name="ControlType">Radio</attr>
    <attr name="ID">Column-9514a407-e6d1-4876-88d1-19dfa2dbb2a4</attr>
    <attr name="MaxIDType"></attr>
    <attr name="Memo">
        <![CDATA[]]>
    </attr>
    <attr name="Options">
        <![CDATA[CodeType:WSCLSS]]>
    </attr>
    <attr name="StyleClass"></attr>
    <attr name="StyleText"></attr>
    <attr name="UIDefaultValue"></attr>
    <attr name="Verify">
        <![CDATA[]]>
    </attr>
    <attr name="DataType">1</attr>
    <attr name="ListColumnWidth">0</attr>
    <attr name="isMandatory">false</attr>
    <attr name="isMaxID">false</attr>
    <attr name="isPrimaryKey">false</attr>
    <attr name="isSearchCondition">false</attr>
    <attr name="isVisiableInForm">true</attr>
    <attr name="isVisiableInList">true</attr>
    <attr name="Length">500</attr>
    <attr name="Precision">0</attr>
     */
    private String name;
    private String code;
    private String type;
    private String controlType;
    private String options;
    private String memo;
    private String verify;
    private String dataType;
    private boolean isMandatory;
    private boolean isPrimaryKey;
    private boolean isSearchCondition;
    private boolean isVisibleInList;
    private boolean isVisibleInForm;
    private int length;
    private int precision;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getControlType() {
        return controlType;
    }

    public void setControlType(String controlType) {
        this.controlType = controlType;
    }

    public String getOptions() {
        return options;
    }

    public void setOptions(String options) {
        this.options = options;
    }

    public String getMemo() {
        return memo;
    }

    public void setMemo(String memo) {
        this.memo = memo;
    }

    public String getVerify() {
        return verify;
    }

    public void setVerify(String verify) {
        this.verify = verify;
    }

    public String getDataType() {
        return dataType;
    }

    public void setDataType(String dataType) {
        this.dataType = dataType;
    }

    public boolean isMandatory() {
        return isMandatory;
    }

    public void setMandatory(boolean mandatory) {
        isMandatory = mandatory;
    }

    public boolean isPrimaryKey() {
        return isPrimaryKey;
    }

    public void setPrimaryKey(boolean primaryKey) {
        isPrimaryKey = primaryKey;
    }

    public boolean isSearchCondition() {
        return isSearchCondition;
    }

    public void setSearchCondition(boolean searchCondition) {
        isSearchCondition = searchCondition;
    }

    public boolean isVisibleInList() {
        return isVisibleInList;
    }

    public void setVisibleInList(boolean visibleInList) {
        isVisibleInList = visibleInList;
    }

    public boolean isVisibleInForm() {
        return isVisibleInForm;
    }

    public void setVisibleInForm(boolean visibleInForm) {
        isVisibleInForm = visibleInForm;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getPrecision() {
        return precision;
    }

    public void setPrecision(int precision) {
        this.precision = precision;
    }


    @JSONField(serialize=false)
    public String getField(){
        return StringUtil.toHumpStr(this.code,false);
    }
    @JSONField(serialize=false)
    public String getDict(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return options.substring(5);
        }
        return null;
    }
    @JSONField(serialize=false)
    public String getTranslate(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("translate:")){
            return options.substring(10);
        }
        return null;
    }
    @JSONField(serialize=false)
    public String getViewOpt(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return "dict=\""+options.substring(5)+"\"";
        }
        if(options.startsWith("translate:")){
            return "uri=\"system/translate/"+options.substring(10)+"\"";
        }
//        if(options.startsWith("FromTable:")){
//            return ":datas=\"options."+code+"\"";
//        }
        return null;
    }
    @JSONField(serialize=false)
    public String getOptType(){
        if(StringUtil.isBlank(options)){
            return null;
        }
        if(options.startsWith("dict:")){
            return "dict";
        }
        if(options.startsWith("translate:")){
            return "translate";
        }
//        if(options.startsWith("FromTable:")){
//            return "table";
//        }
        return null;
    }
//    @JSONField(serialize=false)
//    public String getOptData(){
//       // Options
//        if(StringUtil.isBlank(options)){
//            return null;
//        }
//        if(options.startsWith("Options:")){
//            String data=options.substring(8);
//            List<String> sb=new ArrayList<>();
//            for(String item:data.split(",")){
//
//            }
//            return "{"+String.join(",",sb)+"}";
//
//        }
//        return null;
//    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }
//    public String  getViewOpts() {
////        if(options==null) {
////            return "";
////        }
////        if(options.startsWith("CodeType:")) {
////            return "";
////        }
////        if(options.startsWith("Options:")) {
////            return code+":"+toOptions()+" ";
////        }
////        if(options.startsWith("FromTable:")) {
////            return "Code:new DataSource(\""+ StrKit.firstCharToLowerCase(Parent.CRUDPrefix)+"/"+code+"\").loadData(),";
////        }
//        return "";
//    }
}
